home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)move_win.c V1.6 3/17/95";
- #endif
-
- /*
- | File name: move_win.c
- |========================================================================
- |
- | Copyright (c) 1990 -- V.I. Corporation
- |
- |========================================================================
- */
-
- #include "simulate.h"
- #include "tlc_fundecl.h"
-
-
- /***************** Begin Function Declarations *************/
- LOCAL void move_window V_P_((OBJECT location, DV_POINT *screen_lim, RECTANGLE *curr_pos, RECTANGLE *rel));
- /***************** End Function Declarations *************/
-
- /*
- * Global and local function declarations.
- */
- LOCAL VOID move_window ();
-
- /*
- * MoveDrawport -- move a rectangle withing the screen. Take a rectangle
- * that describes the position of a drawport and a location object the is
- * the current position of the cursor, and allow the user to move an
- * outline of the drawport until he releases the button he's holding.
- */
- /* ARGSUSED */
- void
- MoveDrawport (screen, curr_pos, orig_location)
- OBJECT screen;
- RECTANGLE *curr_pos;
- OBJECT orig_location;
- {
- DV_POINT *ptr, *screen_lim;
- RECTANGLE rel;
- INT indx;
- OBJECT location;
- DV_BOOL done = NO;
-
- /*
- * Get the current position of the cursor and compute its position
- * relative to the corners of the rectangle.
- */
- ptr = VOloScpGet (orig_location);
- rel.ll.x = ptr->x - curr_pos->ll.x;
- rel.ll.y = ptr->y - curr_pos->ll.y;
- rel.ur.x = curr_pos->ur.x - ptr->x;
- rel.ur.y = curr_pos->ur.y - ptr->y;
- screen_lim = VOscSize ();
-
- /*
- * Use a medium gray as the outline color of the rectangle and set the
- * drawing mode to XOR.
- */
- (VOID) GRrgbtoindex (128, 128, 128, &indx);
- (VOID) GRcolor (indx);
- (VOID) GRset (V_DRAW_FUNCTION, V_XOR, V_END_OF_LIST);
- (VOID) GRrectangle (&curr_pos->ll, &curr_pos->ur);
- (VOID) VOscWinEventMask ((ULONG) V_ADD_TO_MASK |
- V_MOTIONNOTIFY |
- V_BUTTONRELEASE |
- V_LEAVENOTIFY,
- 0L);
-
- /*
- * Continue polling the cursor, moving the outline of the rectangle as
- * necessary, until the button is released or the cursor leaves the
- * window.
- */
- while (!done)
- {
- location = VOscWinEventPoll ((INT) V_WAIT);
- switch (VOloType (location))
- {
- case V_MOTIONNOTIFY:
- move_window (location, screen_lim, curr_pos, &rel);
- break;
- case V_BUTTONRELEASE:
- move_window (location, screen_lim, curr_pos, &rel);
- done = YES;
- break;
- case V_LEAVENOTIFY:
- done = YES;
- break;
- default:
- break;
- }
- }
-
- /*
- * Erase the last instance of the outline and restore the drawing mode.
- */
- (VOID) GRrectangle (&curr_pos->ll, &curr_pos->ur);
- (VOID) GRset (V_DRAW_FUNCTION, V_COPY, V_END_OF_LIST);
- }
-
-
- /*
- * move_window -- use the new location object to see if the outline
- * of the rectangle needs to be moved.
- */
- LOCAL void
- move_window (location, screen_lim, curr_pos, rel)
- OBJECT location;
- DV_POINT *screen_lim;
- RECTANGLE *curr_pos;
- RECTANGLE *rel;
- {
- DV_POINT *ptr;
- DV_BOOL change = NO;
- RECTANGLE new_pos;
-
- /*
- * Get the screen position of the cursor, and check to see if the
- * the left and right sides of the box are within the limits of
- * the screen.
- */
- ptr = VOloScpGet (location);
- if (ptr->x - rel->ll.x > 0 && ptr->x + rel->ur.x < screen_lim->x)
- {
- new_pos.ll.x = ptr->x - rel->ll.x;
- new_pos.ur.x = ptr->x + rel->ur.x;
- change = YES;
- }
-
- /*
- * If one of the sides is off the screen, then determine which side it
- * is and adjust it so that it's just at the screen limit.
- */
- else if (ptr->x - rel->ll.x <= 0)
- {
- new_pos.ll.x = 0;
- new_pos.ur.x = rel->ll.x + rel->ur.x;
- }
- else
- {
- new_pos.ur.x = screen_lim->x;
- new_pos.ll.x = screen_lim->x - rel->ur.x - rel->ll.x;
- }
-
- /*
- * Do the same limit checking for the top and bottom of the box.
- */
- if (ptr->y - rel->ll.y > 0 && ptr->y + rel->ur.y < screen_lim->y)
- {
- new_pos.ll.y = ptr->y - rel->ll.y;
- new_pos.ur.y = ptr->y + rel->ur.y;
- change = YES;
- }
- else if (ptr->y - rel->ll.y <= 0)
- {
- new_pos.ll.y = 0;
- new_pos.ur.y = rel->ll.y + rel->ur.y;
- }
- else
- {
- new_pos.ur.y = screen_lim->y;
- new_pos.ll.y = screen_lim->y - rel->ur.y - rel->ll.y;
- }
-
- /*
- * Check to see if the box has moved at all and if it has then
- * erase the old image of the box and draw a new one at the new
- * position.
- */
- if (new_pos.ll.x != curr_pos->ll.x)
- change = YES;
- if (new_pos.ll.y != curr_pos->ll.y)
- change = YES;
- if (new_pos.ur.x != curr_pos->ur.x)
- change = YES;
- if (new_pos.ur.y != curr_pos->ur.y)
- change = YES;
-
- if (change)
- {
- (VOID) GRrectangle (&curr_pos->ll, &curr_pos->ur);
- (VOID) GRrectangle (&new_pos.ll, &new_pos.ur);
- curr_pos->ll.x = new_pos.ll.x;
- curr_pos->ll.y = new_pos.ll.y;
- curr_pos->ur.x = new_pos.ur.x;
- curr_pos->ur.y = new_pos.ur.y;
- }
- }
-